/**
 * 
 */

package homework.homework5.problem1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * @author hoang.pt
 *
 */
public class ComputerList {

	/**
	 * @var ArrayList, store list of computer
	 */
	protected ArrayList<Computer> listComputer;
	
	/**
	 * constructor
	 */
	public ComputerList() {
		listComputer = new ArrayList<Computer>(1);
	}

	/**
	 * add computer into List
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	void addComputer() throws NumberFormatException, IOException {
		
		//init answer
		String answer = "y";
		
		//read from System.in
		InputStreamReader reader = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(reader);
		
		//check answer
        while (answer.equals("Y") || answer.equals("y")) {
        	//add another
            System.out.println("Enter computer information.");
            System.out.println("id: ");
            int id = Integer.parseInt(in.readLine());

            System.out.println("name: ");
            String name = in.readLine();

            System.out.println("brand: ");
            String brand = in.readLine();

            System.out.println("price: ");
            double p = Double.parseDouble(in.readLine());
            Double price = new Double(p);
    		
            //add into list
            Computer computer = new Computer(id, name, brand, price);
            listComputer.add(computer);
            
            //answer add yes or no continue
            System.out.println("Continue or not (Y/N)");
            answer = in.readLine();
        	
        }
		
		//back to submenu
        P1Demo.subMenu("computer");
	}
	
	/**
	 * display all compter in list
	 * @author hoang.pt
	 * @throws IOException 
	 */
	void displayAll() throws IOException {
		
		//iterator
		for (Computer computer:listComputer) {
			System.out.println(computer);
		}
		
		//for (int i=0; i<listComputer.size(); i++) {
		//	System.out.println(listComputer.get(i));
		//}
		
		P1Demo.subMenu("computer");
		
	}
	
	/**
	 * search computer
	 */
	void searchComputer() {
		
		
	}
}
